home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98b.txt / 000111_icon-group-sender _Mon Jun 29 08:41:34 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.8/8.8.7) with SMTP id IAA06696
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Mon, 29 Jun 1998 08:41:33 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA21982; Mon, 29 Jun 1998 08:41:22 -0700
  7. Sender: rwg@fns.com
  8. Message-Id: <35970836.34465163@fns.com>
  9. Date: Sun, 28 Jun 1998 23:21:26 -0400
  10. From: Robbie Gilbert <rwg@fns.com>
  11. Organization: Fujitsu Network Communications
  12. X-Mailer: Mozilla 4.05 [en] (X11; I; SunOS 5.5.1 sun4u)
  13. Mime-Version: 1.0
  14. To: jeffery@segfault.cs.utsa.edu
  15. Cc: icon-group@optima.CS.Arizona.EDU
  16. Subject: Re: Forcing Generator to Return a List of Values
  17. References: <199806270618.BAA10281@segfault.cs.utsa.edu>
  18. Content-Type: text/plain; charset=us-ascii
  19. Content-Transfer-Encoding: 7bit
  20. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  21. Status: RO
  22. Content-Length: 1928
  23.  
  24. Clinton Jeffery wrote:
  25.  
  26. > Hi,
  27. >
  28. > I am sure you got deluged with answers, so I will be brief.  Yes, it is
  29. > useful occasionally to collect all the results from a generator and put them
  30. > in a list, and no, there isn't a standard library function.  In fact, if you
  31. > think about it, a library procedure would not help you.  You need to write
  32. > the code yourself, either in your own helper procedure, or directly in the
  33. > place where you've got the generator and need the list.  Fortunately, as you
  34. > say, its only a couple of lines.
  35. >
  36. > Clint Jeffery
  37.  
  38. Clint,
  39.  
  40. Thanks for the response.  Actually yours was the only one I've gotten so far.
  41. I think a procedure can help; how about:
  42.  
  43.      procedure collectAll (expressions)
  44.        local results
  45.        results := []
  46.  
  47.        every C := !expressions do
  48.          every result := |@C do
  49.            results |||:= [result]
  50.  
  51.        return results
  52.      end
  53.  
  54. This procedure is invoked using braces as explained on page 116 of the The Icon
  55. Programming Language (3rd ed.), in the section on user-defined control
  56. structures:
  57.  
  58.      # args is some list
  59.      foo := collectAll { ! args }
  60.  
  61. This procedure takes a comma-separated list of co-expressions (in this example,
  62. there is only one, !args), grabs all the results and returns them in a list.
  63. (This may need some refinement to work properly for all kinds of expressions,
  64. I just finished writing it so I haven't tested it thoroughly yet.  Also the
  65. list concatenation may not be very efficient--there may be a better way but I'm
  66. new to this language.)
  67.  
  68. Hopefully I can pass any valid expression as an arg and get a list of the
  69. results back.  This is what I was trying to accomplish and seems to be fairly
  70. general.  This seems like a natural, common task and given Icon's strengths in
  71. this type of thing I thought there would already be something like this in the
  72. program library--didn't want to reinvent the wheel.
  73.  
  74. Thanks,
  75.  
  76. Robbie
  77. rwg@fns.com
  78.  
  79.  
  80.